package sv.com.renacempleo.web.controller.red;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import sv.com.renacempleo.web.controller.BaseController;
import sv.com.renacempleo.web.util.DBContext;

@SuppressWarnings("serial")
@Controller
@RequestMapping("/sucursalesEmpresas")
public class RedEmpresaSucursalesController extends BaseController{
	
	@RequestMapping(value = "/findSucursalesEmpresa", method = {RequestMethod.POST})
	public void findSucursalesEmpresa(HttpServletResponse response, 
			@RequestParam (required = false) Long redEmpresaFolio){
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			List<Object[]> list = DBContext.getRedEmpresaSucursalesDao().findAllByEmpresa(redEmpresaFolio);
			result.put("sucursales",  JSONArray.fromObject(list));
		}catch (Exception e) {
			logger.error("Exception: ", e);
		}
		serializeObject(result, response);
	}

}
